home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / FRM_ALRT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-01  |  7.7 KB  |  272 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <VDI.H>
  9. #include <OSBIND.H>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "XA_DEFS.H"
  15. #include "BOX3D.H"
  16. #include "FRM_ALRT.H"
  17. #include "K_DEFS.H"
  18. #include "RESOURCE.H"
  19. #include "OBJECTS.H"
  20. #include "WATCHBOX.H"
  21. #include "C_WINDOW.H"
  22. #include "STD_WIDG.H"
  23. #include "system.h"
  24. #include "watchbox.h"
  25. #include "frm_util.h"
  26.  
  27. /*
  28.     Form_alert handler v2.1
  29. */
  30. short click_alert_widget(XA_WINDOW *wind, XA_WIDGET *widg);
  31.  
  32. short do_form_alert(short default_button, char *alert, short owner)
  33. {
  34.     XA_WINDOW *alert_window;
  35.     XA_WIDGET_LOCATION dialog_toolbar_loc={LT,3,20};
  36.     short x,y,w,h=0,n_lines=0,n_buttons=0,icon,max_w=0,m_butt_w=0;
  37.     short ty,th,b;
  38.     short f,pnt[10];
  39.     char alert_text[5][100];    /* texts to display in the alert */
  40.     char button_text[3][20];    /* text for buttons */
  41.     short button_w[3];
  42.     char *t;
  43.     OBJECT *alert_form;
  44.     OBJECT *alert_icons;
  45.  
  46.     for(ty=0; ty<5; ty++) alert_text[ty][0]='\0';
  47.     
  48.     if (alert[0]!='[') return 0;
  49.     t=alert+1;
  50.     for(f=1; (t[f]!=']')&&(t[f]!='\0'); f++);    /* Search for closing bracket on first field */
  51.     if (t[f]!=']') return 0;
  52.  
  53.     t[f]='\0';
  54.     icon=atoi(t);                /* calculate the icon */
  55.     
  56.     t+=f+1;
  57.     if (t[0]!='[') return 0;
  58.     
  59.     t++;
  60.     for(f=0; (t[f]!=']')&&(t[f]!='\0');f++)        /* Strip out the text lines */
  61.     {
  62.         if (t[f]=='|')
  63.         {
  64.             t[f]='\0';
  65.             vqt_extent(V_handle,t,pnt);
  66.             w=pnt[2]-pnt[0];
  67.             th=pnt[7]-pnt[1];
  68.             h+=th;
  69.             if (w>max_w) max_w=w;
  70.             sprintf(alert_text[n_lines],"%s",t);
  71.             n_lines++;
  72.             t+=f+1; f=0;
  73.         }
  74.     }
  75.     if (t[f]!=']') return 0;
  76.     t[f]='\0';
  77.     vqt_extent(V_handle,t,pnt);
  78.     w=pnt[2]-pnt[0];
  79.     th=pnt[7]-pnt[1];
  80.     h+=th;
  81.     if (w>max_w) max_w=w;
  82.     sprintf(alert_text[n_lines],"%s",t);
  83.     n_lines++;
  84.  
  85.     t+=f+1;
  86.     if (t[0]!='[') return 0;
  87.     t++;
  88.  
  89.     for(f=0; (t[f]!=']')&&(t[f]!='\0');f++)        /* Strip out the text lines */
  90.     {
  91.         if (t[f]=='|')
  92.         {
  93.             t[f]='\0';
  94.             vqt_extent(V_handle,t,pnt);
  95.             button_w[n_buttons]=pnt[2]-pnt[0]+3*display.c_max_w;
  96.             m_butt_w+=button_w[n_buttons];
  97.             sprintf(button_text[n_buttons],"%s",t);
  98.             n_buttons++;
  99.             t+=f+1; f=0;
  100.         }
  101.     }
  102.     if (t[f]!=']') return 0;
  103.     t[f]='\0';
  104.     vqt_extent(V_handle,t,pnt);
  105.     button_w[n_buttons]=pnt[2]-pnt[0]+3*display.c_max_w;
  106.     m_butt_w+=button_w[n_buttons];
  107.     sprintf(button_text[n_buttons],"%s",t);
  108.     n_buttons++;
  109.     
  110.     if (m_butt_w>max_w) max_w=m_butt_w;
  111.     
  112.     w=max_w + 50;
  113.     
  114.     h+=5*th;
  115.     x=(display.w-w)/2;
  116.     y=(display.h-h)/2;
  117.  
  118. /* Create a copy of the alert box template */
  119.     alert_form=CloneForm(ResourceTree(system_resources,ALERT_BOX));
  120.     alert_icons=ResourceTree(system_resources,ALERT_ICONS);
  121.     alert_form->ob_width=w;
  122.     alert_form->ob_x=x;
  123.     alert_form->ob_y=y;
  124.  
  125.     if ( display.colours<16 )            /* hmm... perhaps this should be done in */
  126.     {                                    /* "color mode" too? <mk> */
  127.         long obspec=(long)alert_form->ob_spec;
  128.         obspec &= ~0xfL ;
  129.         obspec |= (display.dial_colours.bg_col & 0xf);    /* interior color */
  130.         alert_form->ob_spec = (void*)obspec;
  131.     }
  132.  
  133.     for(f=ALR_IC_DRIVE; f<=ALR_IC_BOMB; f++)
  134.     {
  135.         ((ICONBLK*)(alert_icons+f)->ob_spec)->ib_xicon=((ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec)->ib_xicon;
  136.         ((ICONBLK*)(alert_icons+f)->ob_spec)->ib_yicon=((ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec)->ib_yicon;
  137.     }
  138.     
  139.     switch(icon)    /* Setup the correct icon for this alert */
  140.     {
  141.         case 1:
  142.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_WARNING)->ob_spec;
  143.             break;
  144.         case 2:
  145.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_QUESTION)->ob_spec;
  146.             break;
  147.         case 3:
  148.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_STOP)->ob_spec;
  149.             break;
  150.         case 4:
  151.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_INFO)->ob_spec;
  152.             break;
  153.         case 5:
  154.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_DRIVE)->ob_spec;
  155.             break;
  156.         case 6:
  157.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_BOMB)->ob_spec;
  158.             break;
  159.         case 0:
  160.         default:
  161.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_SYSTEM)->ob_spec;
  162.             break;
  163.     }
  164.     
  165.     for(f=0; f<5; f++)                /* Fill in texts */
  166.         sprintf(((TEDINFO*)alert_form[ALERT_T1+f].ob_spec)->te_ptext,"%s",alert_text[f]);
  167.     
  168.     x=w-m_butt_w;                     /* space the buttons evenly */
  169.     b=x/(n_buttons+1);    
  170.     x=b;
  171.     
  172.     for(f=0; f<n_buttons; f++)        /* Fill in & show buttons */
  173.     {
  174.         if ( display.colours<16 )
  175.         {
  176.             /* Make sure we can *READ* the button text: */
  177.             alert_form[ALERT_BUT1+f].ob_flags &= ~FLD3DANY ;    /* clear 3D flags */
  178.             /* (this is just a stopgag measure - apparently the 3D button code
  179.                 isn't quite mono-compatible yet...) */
  180.         }
  181.         sprintf((char*)alert_form[ALERT_BUT1+f].ob_spec,"%s",button_text[f]);
  182.         alert_form[ALERT_BUT1+f].ob_width=button_w[f];
  183.         alert_form[ALERT_BUT1+f].ob_x=x;
  184.         alert_form[ALERT_BUT1+f].ob_flags&=~(HIDETREE|DEFAULT);
  185.         alert_form[ALERT_BUT1+f].ob_state=0;
  186.         x+=button_w[f]+b;
  187.     }
  188.     
  189.     if (default_button)                /* Set the default button if it was specified */
  190.         alert_form[ALERT_BUT1+default_button-1].ob_flags|=DEFAULT;
  191.     
  192.     for(f=n_buttons; f<3; f++)        /* Hide unused buttons */
  193.         alert_form[ALERT_BUT1+f].ob_flags|=HIDETREE;
  194.  
  195. /* Create a window and attach the alert object tree to it */
  196.     alert_window=create_window(owner, NAME|MOVE|STORE_BACK|NO_WORK, alert_form->ob_x, alert_form->ob_y, 
  197.                                     alert_form->ob_width+10, display.c_max_h+16+alert_form->ob_height);
  198.  
  199.     dialog_toolbar_loc.y=display.c_max_h+10;
  200.     set_toolbar_widget(alert_window, dialog_toolbar_loc, alert_form);
  201.     
  202. /* Change the click & drag behaviours for the alert box widget, because alerts return a number */
  203. /* 1 to 3, not an object index. */
  204.     alert_window->widgets[XAW_TOOLBAR].behaviour[XACB_CLICK]=&click_alert_widget;
  205.     alert_window->widgets[XAW_TOOLBAR].behaviour[XACB_DRAG]=&click_alert_widget;
  206.     ((XA_WIDGET_TREE*)alert_window->widgets[XAW_TOOLBAR].stuff)->owner=owner;
  207.     
  208.     alert_window->active_widgets|=NO_REDRAWS;    /* We don't want any redraw messages  */
  209.                                             /* - the widget handler will take care of it */
  210.     alert_window->is_open=TRUE;
  211.  
  212. /* Set the window title to be the clients name to avoid confusion */
  213.     alert_window->widgets[XAW_TITLE].stuff=(void*)clients[owner].name;
  214.     
  215.     v_hide_c(V_handle);
  216.     pull_wind_to_top(alert_window);
  217.     display_window(alert_window);
  218.     v_show_c(V_handle,1);
  219.     
  220.     return 0;
  221. }
  222.  
  223. /*
  224.     Small handler for clicks on an alert box
  225. */
  226. short click_alert_widget(XA_WINDOW *wind, XA_WIDGET *widg)
  227. {
  228.     short x,y,sel_b=-1,f,b;
  229.     unsigned long retv=XA_OK;
  230.     XA_WIDGET_TREE *wt=(XA_WIDGET_TREE*)widg->stuff;
  231.     OBJECT *alert_form;
  232.  
  233.     if (window_list!=wind)            /* You can only work alerts when they are on top */
  234.         return FALSE;
  235.  
  236.     alert_form=wt->tree;
  237.  
  238.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  239.  
  240.     f=find_object(alert_form, 0, 10, x+widg->click_x, y+widg->click_y);
  241.  
  242.     if (((f>=ALERT_BUT1)            /* Did we click on a valid button? */
  243.         &&(f<ALERT_BUT1+3))
  244.         &&(!(alert_form[f].ob_flags&HIDETREE)))
  245.     {
  246.         clear_clip();
  247.     
  248.         b=watch_object(alert_form, f, SELECTED, 0);
  249.     
  250.         if (b)
  251.             sel_b=f+1-ALERT_BUT1;
  252.     
  253.         if (sel_b>-1)                    /* If the click was definite, we return the button & close the window */
  254.         {
  255.             clients[wt->owner].waiting_pb->intout[0]=sel_b;
  256.             Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long),&retv);    /* Write success to clients reply pipe to unblock the process */
  257.  
  258.             v_hide_c(V_handle);
  259.             display_windows_below(wind);
  260.             v_show_c(V_handle,1);
  261.  
  262.             wind->is_open=FALSE;
  263.  
  264.             delete_window(wind);
  265.             
  266.             DeleteClone(alert_form);    /* Delete this copy of the alert form */
  267.         }
  268.     }
  269.     
  270.     return FALSE;
  271. }
  272.